package com.rs.game.player.content;

import com.rs.game.player.Player;
import com.rs.net.decoders.WorldPacketsDecoder;

/**
 * @author Swirl
 */
public class MakePlank {
	public static int CFG = 403; // <-- This is the plank making interface.

	public static void handleButtons(Player player, int componentId, int packetId) {
		if (componentId == 12) {
			if (packetId == WorldPacketsDecoder.ACTION_BUTTON1_PACKET) {
				if (player.getInventory().containsItem(1511, 1) && player.getInventory().containsItem(995, 50)) {
					player.getInventory().deleteItem(995, 50);
					player.getInventory().deleteItem(1511, 1);
					player.getInventory().addItem(960, 1);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON2_PACKET) {
				if (player.getInventory().containsItem(1511, 5) && player.getInventory().containsItem(995, 250)) {
					player.getInventory().deleteItem(995, 250);
					player.getInventory().deleteItem(1511, 5);
					player.getInventory().addItem(960, 5);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON3_PACKET) {
				if (player.getInventory().containsItem(1511, 10) && player.getInventory().containsItem(995, 500)) {
					player.getInventory().deleteItem(995, 500);
					player.getInventory().deleteItem(1511, 10);
					player.getInventory().addItem(960, 10);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON4_PACKET) {
				player.closeInterfaces();
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON5_PACKET) {
				if (player.getInventory().containsOneItem(1511) && player.getInventory().containsOneItem(995)) {
					int totalPlanks = player.getInventory().getNumerOf(1511);
					int totalValue = totalPlanks * 50;

					if (player.getInventory().containsItem(995, totalValue)) {
						player.getInventory().deleteItem(1511, totalPlanks);
						player.getInventory().deleteItem(995, totalValue);
						player.getInventory().addItem(960, totalPlanks);
						player.closeInterfaces();
					}
				}
			}
		} else if (componentId == 13) {
			if (packetId == WorldPacketsDecoder.ACTION_BUTTON1_PACKET) {
				if (player.getInventory().containsItem(1521, 1) && player.getInventory().containsItem(995, 125)) {
					player.getInventory().deleteItem(995, 125);
					player.getInventory().deleteItem(1521, 1);
					player.getInventory().addItem(8778, 1);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON2_PACKET) {
				if (player.getInventory().containsItem(1511, 5) && player.getInventory().containsItem(995, 625)) {
					player.getInventory().deleteItem(995, 625);
					player.getInventory().deleteItem(1521, 5);
					player.getInventory().addItem(8778, 5);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON3_PACKET) {
				if (player.getInventory().containsItem(1521, 10) && player.getInventory().containsItem(995, 1250)) {
					player.getInventory().deleteItem(995, 1250);
					player.getInventory().deleteItem(1521, 10);
					player.getInventory().addItem(8778, 10);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON4_PACKET) {
				player.closeInterfaces();
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON5_PACKET) {
				if (player.getInventory().containsOneItem(1521) && player.getInventory().containsOneItem(995)) {
					int totalPlanks = player.getInventory().getNumerOf(1521);
					int totalValue = totalPlanks * 125;

					if (player.getInventory().containsItem(995, totalValue)) {
						player.getInventory().deleteItem(1521, totalPlanks);
						player.getInventory().deleteItem(995, totalValue);
						player.getInventory().addItem(8778, totalPlanks);
						player.closeInterfaces();
					}
				}
			}
		} else if (componentId == 14) {
			if (packetId == WorldPacketsDecoder.ACTION_BUTTON1_PACKET) {
				if (player.getInventory().containsItem(6333, 1) && player.getInventory().containsItem(995, 250)) {
					player.getInventory().deleteItem(995, 250);
					player.getInventory().deleteItem(6333, 1);
					player.getInventory().addItem(8780, 1);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON2_PACKET) {
				if (player.getInventory().containsItem(6333, 5) && player.getInventory().containsItem(995, 1250)) {
					player.getInventory().deleteItem(995, 1250);
					player.getInventory().deleteItem(6333, 5);
					player.getInventory().addItem(8780, 5);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON3_PACKET) {
				if (player.getInventory().containsItem(6333, 10) && player.getInventory().containsItem(995, 2500)) {
					player.getInventory().deleteItem(995, 1250);
					player.getInventory().deleteItem(6333, 10);
					player.getInventory().addItem(8780, 10);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON4_PACKET) {
				player.closeInterfaces();
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON5_PACKET) {
				if (player.getInventory().containsOneItem(6333) && player.getInventory().containsOneItem(995)) {
					int totalPlanks = player.getInventory().getNumerOf(6333);
					int totalValue = totalPlanks * 250;

					if (player.getInventory().containsItem(995, totalValue)) {
						player.getInventory().deleteItem(6333, totalPlanks);
						player.getInventory().deleteItem(995, totalValue);
						player.getInventory().addItem(8780, totalPlanks);
						player.closeInterfaces();
					}
				}
			}
		} else if (componentId == 14) {
			if (packetId == WorldPacketsDecoder.ACTION_BUTTON1_PACKET) {
				if (player.getInventory().containsItem(6332, 1) && player.getInventory().containsItem(995, 750)) {
					player.getInventory().deleteItem(995, 250);
					player.getInventory().deleteItem(6332, 1);
					player.getInventory().addItem(8782, 1);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON2_PACKET) {
				if (player.getInventory().containsItem(6332, 5) && player.getInventory().containsItem(995, 3750)) {
					player.getInventory().deleteItem(995, 1250);
					player.getInventory().deleteItem(6332, 5);
					player.getInventory().addItem(8782, 5);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON3_PACKET) {
				if (player.getInventory().containsItem(6332, 10) && player.getInventory().containsItem(995, 7500)) {
					player.getInventory().deleteItem(995, 1250);
					player.getInventory().deleteItem(6332, 10);
					player.getInventory().addItem(8782, 10);
					player.closeInterfaces();
				}
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON4_PACKET) {
				player.closeInterfaces();
			} else if (packetId == WorldPacketsDecoder.ACTION_BUTTON5_PACKET) {
				if (player.getInventory().containsOneItem(6332) && player.getInventory().containsOneItem(995)) {
					int totalPlanks = player.getInventory().getNumerOf(6332);
					int totalValue = totalPlanks * 750;

					if (player.getInventory().containsItem(995, totalValue)) {
						player.getInventory().deleteItem(6332, totalPlanks);
						player.getInventory().deleteItem(995, totalValue);
						player.getInventory().addItem(8782, totalPlanks);
						player.closeInterfaces();
					}
				}
			}
		}
	}

	public static void setIcomponents(Player player) {
		player.getPackets().sendIComponentText(403, 20, "Wood<br>Cost = 50");
		player.getPackets().sendIComponentText(403, 21, "Oak<br>Cost = 125");
		player.getPackets().sendIComponentText(403, 22, "Teak<br>Cost = 250");
		player.getPackets().sendIComponentText(403, 23, "Mahogany<br>Cost = 750");
	}
}
